package com.itheima.streamdemo.mystream;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;

public class MyStream6 {
    public static void main(String[] args) {
        ArrayList<Integer> list = new ArrayList<>();
        for (int i = 1; i <= 10; i++) {
            list.add(i);
        }

        /**
         * @deprecated:
         *      filter(): 负责过滤数据
         *      collect(): 负责收集数据
         *          获取流中剩余的数据,但是并不负责创建容器,也不负责把数据添加到容器中
         *      Collectors.toList():
         *          在底层会创建一个list集合,并把所有的数据添加到list集合中
         *
         * */
        List<Integer> list1 = list.stream().filter(number -> number % 2 == 0)
                .collect(Collectors.toList());

        list1.forEach(number -> System.out.println(number));

        Set<Integer> set = list.stream().filter(number -> number % 2 == 0)
                .collect(Collectors.toSet());
        set.forEach(number -> System.out.println(number));

    }
}
